#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using u64 = unsigned long long;
using u32 = unsigned;
using u128 = unsigned __int128;
struct st {
    string u, a, b;
};
int ans[4];
map<pair<int, int>, int> mp;
const int l1 = 25200, r1 = 32400, l2 = 39600, r2 = 46800, l3 = 79200, r3 = 86400;

void check(st p) {
    string u = p.u, a = p.a, b = p.b;
    int t1 = stoi(u.substr(8));
    int x = stoi(b.substr(0, 2));
    int y = stoi(b.substr(3, 2));
    int z = stoi(b.substr(6));
    int t = x * 3600 + y * 60 + z;
    int pos = -1;
    if(t >= l1 && t <= r1) {
        pos = 1;
    }else if(t >= l2 && t <= r2) {
        pos = 2;
    }else if(t >= l3 && t <= r3 || t >= 0 && t <= 3600){
        pos = 3;
    }
    if(pos == -1) return;
    if(!mp.count({t1, pos})) {
        mp[{t1, pos}]++;
        ans[pos]++;
    }
    
}

void solve() {
    int n;
    cin >> n;
    string m, h;
    cin >> h >> m;
    vector<st> vec;
    for(int i = 0; i < n; i++) {
        string u, a, b;
        cin >> u >> a;
        if(a.substr(0, 4) == h && a.substr(5, 2) == m){
            vec.push_back({u, a, b});
        }
    }
    for(auto p : vec) {
        check(p);
    }
    cout << ans[1] << ' ' << ans[2] << ' ' << ans[3] << endl;
}

int main() {
    ios::sync_with_stdio(false), cin.tie(0);
    int t = 1;
//     cin >> t;
    while(t--) solve();
    return 0;
}